package distributedbank.sensor;

/**
 * One Sensor for one BankBranch. Sensor receives HeatBeatMessage from
 * BankBranch regularly. Whenever it fails to receive the HBM within a time
 * threshold T = 400ms, send a SuspectRequest to FailureDetectionVoter.
 * 
 * Afterwards, when it receives HBM again, it sends a SuspectRequest to
 * FailureDetectionVoter again.
 */
public class Sensor {
	private int branchId;
	private boolean suspected;

	// DEFINE T
	private int T = 400;

	public Sensor(int branchId) {
		this.branchId = branchId;
		this.suspected = false;
	}

	public static void main(String[] args) {
		if (args.length != 1) {
			System.out
					.println("Error: You must specify the branch ID on the command-line.");
			System.exit(1);
		} else {
			int branchId = Integer.valueOf(args[0]);
			new Sensor(branchId).run();
		}
	}

	/**
	 * Listen to HeartBeatMessage from bank branch with id = branchId. If
	 * suspected == false and time interval exceeds T, send a SuspectRequest to
	 * FailureDetectionVoter, change suspected to true. If suspected == true and
	 * receives HBM, send SuspectRequest to FailureDetectionVoter, change
	 * suspected to false.
	 */
	private void run() {
		// TODO
	}
}
